/*
 * TcpTsMediaCaster.h
 *
 *  Created on: 2019年2月28日
 *      Author: terry
 */

#ifndef TCPTSMEDIACASTER_H_
#define TCPTSMEDIACASTER_H_

#include "BasicTsMediaCaster.h"
#include "MediaPacketQueue.h"
#include "TcpServer.h"
#include "TsCaster.h"


namespace av
{


class TcpTsMediaCaster : public BasicTsMediaCaster, public TcpServer
{
public:
    TcpTsMediaCaster();
    virtual ~TcpTsMediaCaster();

    virtual int open(const std::string& ip, uint16_t port, const MediaFormat& fmt);

    virtual void close();

    virtual bool isOpen();

    virtual void removeAllTarget();

protected:
    virtual void writePacket(uint8_t* data, int size, int64_t pts, int flags);

    virtual void writeMediaPacket(MediaPacketPtr& pkt);

protected:
    virtual TcpConnectionPtr create(evutil_socket_t fd);
    virtual void onClose(TcpConnectionPtr& conn);

protected:
    void closeAll();

    void dispatchPacket(TcpConnectionPtr& connection, MediaPacketPtr& pkt);

protected:


};


} /* namespace av */

#endif /* TCPTSMEDIACASTER_H_ */
